import java.util.*;

public class Match
{
	// Game states
	public static final int NO_GAME = 0;
	public static final int FIND_GAME = 1;
	public static final int FULL_GAME = 2;

	// Game types
	public static final int FIVE_IH = 0;
	public static final int THREE_IH = 1;
	public static final int ONE_VS_ONE = 2;

	// Mod list
	public static final int NONE = 0;

	public int state = NO_GAME;
	public ArrayList<String> playerlist = new ArrayList<String>();

	public int type = 0;
	public int mods = 0;

	// AFK check stuff
	public HashSet<String> notAFK = new HashSet<String>();
	public AFKCheck thread = null;

	public static String getType(int type)
	{
		String ret = "";
		switch (type)
		{
		case FIVE_IH:
			ret = "Summoner's Rift Inhouse";
			break;

		case THREE_IH:
			ret = "Twisted Treeline Inhouse";
			break;

		case ONE_VS_ONE:
			ret = "1v1 test";
			break;
		}

		return ret;
	}

	public String getType()
	{
		return getType(true);
	}

	public String getType(boolean include)
	{
		String ret = "";
		switch (type)
		{
		case FIVE_IH:
			ret = "Summoner's Rift Inhouse";
			break;

		case THREE_IH:
			ret = "Twisted Treeline Inhouse";
			break;

		case ONE_VS_ONE:
			ret = "1v1 test";
			break;
		}

		if (include)
			ret += " (" + playerlist.size() + "/" + maxPlayers() + " players)";

		return ret;
	}

	public int maxPlayers()
	{
		if (type == FIVE_IH)
			return 10;
		else if (type == THREE_IH)
			return 6;
		else if (type == ONE_VS_ONE)
			return 2;

		return 0;
	}

	public boolean full()
	{
		return (playerlist.size() == maxPlayers());
	}

	public void startAFKCheck()
	{
		if (thread != null)
			thread.interrupt();

		thread = new AFKCheck(300000, this);
		thread.start();
	}

	public void endAFKCheck()
	{
		if (thread != null)
			thread.interrupt();

		thread = null;

		notAFK = new HashSet<String>();
	}

	public boolean canSnipe()
	{
		if (thread == null)
			return true;

		return thread.sniping;
	}

	public void timedOut()
	{
		playerlist = new ArrayList<String>();
		for (String nick : notAFK)
			playerlist.add(nick);
		notAFK = new HashSet<String>();

		if (playerlist.size() < maxPlayers())
			state = FIND_GAME;

		LeagueBot.sendMsg(LeagueBot.channel, "AFK check failed - Some players were kicked from the pool");

		DataManager dm = DataManager.getInstance();
		dm.clearPools();
		dm.dumpLobby();
	}
}
